# coding=utf-8
__author__ = 'fengoupeng'

import time, sys, re, redis, json
sys.path.append('..')

def ouput_fail_task():
    redis_tasks = {
        # 'host':     '101.201.196.82',
        # 'host':     '10.174.8.70',
        'host':     '127.0.0.1',
        'port':     6379,
        'password': 'haizhi@)',
        'database': 7,
        'key':      'fail_tasks',
    }
    redis_db = redis.Redis(host=redis_tasks['host'], password=redis_tasks['password'], port=redis_tasks['port'], db=redis_tasks['database'])
    urls = {}
    fail_tasks = redis_db.lrange(redis_tasks['key'], 0, -1)
    for fail_task in fail_tasks:
        json_task = json.loads(fail_task)
        if json_task.get('doc_type') != 'index':
            continue
        #if json_task.get('page_num') != '1':
        #    continue
        if json_task.get('site_id') != '3':
            continue
        url = json_task.get('url')
        urls[url] =json_task.get('page_num')
    keys = urls.keys()
    keys.sort()
    for key in keys:
        array = urls[key]
        print key, array

if __name__ == '__main__':
    ouput_fail_task()
